<div id="registerDiv" class="login_wrapper">
    <div id="register" class="animate form register_form">
        <section class="login_content">
            <form action="javascript:function(0);">
                <h1>Create Account</h1>
                <div>
                    <input type="text" v-model="user.userName" class="form-control" placeholder="Username" required=""/>
                </div>
                <div>
                    <input type="email" v-model="user.email" class="form-control" placeholder="Email" required=""/>
                </div>
                <div>
                    <input type="password" v-model="user.password" class="form-control" placeholder="Password" required=""/>
                </div>
                <div>
                    <a class="btn btn-default submit" href="javascript:function(0);" @click="register()">Submit</a>
                </div>

                <div class="clearfix"></div>

                <div class="separator">
                    <p class="change_link">Already a member ?
                        <a href="/login" class="to_register"> Log in </a>
                    </p>

                    <div class="clearfix"></div>
                    <br/>

                    <div>
                        <h1><i class="fa fa-paw"></i> Hello World!</h1>
                        <p>©2021 All Rights Reserved. Hello World! is a Bootstrap 3 template.</p>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<script type="text/javascript">
    var registerVue = new Vue({
        el: "#registerDiv",
        data: {
            user: {
                email: "",
                userName: "",
                password: "",
            },
        },
        methods: {
            
            register: function () {
                var webUser = this;
                if(webUser.user.userName == "" || webUser.user.email == "" || webUser.user.password == ""){
                    layer.msg("Please input info !",{ icon : 0});
                    return;
                }
                $.ajax({
                    //1、数据将要发送到哪里
                    url: "/api/user",
                    //2、通过什么方式发送
                    type: "post",
                    //3、发送的数据类型是什么
                    contentType: "application/json",
                    //4、需要发送的数据是什么（可以没有数据发送）
                    //data: {"userName": webUser.user.userName, "password": webUser.user.password,"email":webUser.user.email},
                    data: JSON.stringify(webUser.user),
                    //5、后端返回的数据类型
                    //dataType:"json",
                    //6、返回成功后的表现（通过回调函数来实现）
                    success: function (data) {
                        if(data.status == 200){
                            location.href = "/login";
                        }else{
                            layer.msg(data.message,{ icon : 0});
                        }
                    },
                    error:function(data){
                        layer.msg(data.message,{ icon : 0});
                    },
                });
            }
        }
    });
</script>